<template>
  <work-template v-model="detailForm" @submitOn="submitOn" :flowId="flowId"
                 @closeSelectedTag="closeSelectedTag" :butShow="bool">
    <div slot="form" class="container-div">
      <annal-basi-info v-model="inspectDetail" :state="isEdit"/>

      <processing-annual v-model="detailForm" :state="isEdit" ref="refDetailForm"/>
    </div>
  </work-template>
</template>

<script>


import {
  addInspection, feedbackList,
  updateInspection, getInspectionDetails

} from "@/api/cwgd/inspectApi.js";
import {
  getWorkOrder
} from "@/api/cwgd/cwgdApi.js";


import LinkageSelect from "../../components/linkageSelect";
import ImgUpload from "../components/ImgUpload/index.vue";
import {
  getFindCarWorkOrderInfoVo,
} from "@/api/cwgd/maintenanceApi.js";
export default {
  name: "InspectDetails",
  components: {
    annalBasiInfo: () => import('../components/annualInspection/annalBasiInfo.vue'),
    processingAnnual: () => import('../components/annualInspection/processingAnnual.vue')
  },

  data() {
    return {
      detailForm: {
        //年检信息
        workId: "",
        inspectionTime: "",
        onlineOffline: "",
        inspectionNextTime: "",
        expireOnlineOffline: "",
        inspectionPrice: "",
        inspectionAgentPrice: "",
        comprehensivePrice: "",
        twoDimensionPrice: "",
        otherPrice: "",
        inspectionAllPrice: "",
        inspectionIdenUrl: "",
        inspectionInvoiceUrl: "",
        remark: "",


        //车辆信息
        carNo: "",
        vinNo: "",
        brandName: "",
        seriesName: "",
        modelName: "",
        propertyRightName: "",
        ascription: "",
        orderCode: "",
        customerName: "",
        contractType: "",
        carNature: "",
        businessType: "",
        registerTime: "",
        seatNum:"",
        fuelType:'',
        lastOnlineOffline: "",
        inspectionLastTime: "",
        attachmentUrl: "",
        carId: '',
        isOurCompanyInspection:'',
        isFirstInspect:'',
        inStorageInspect:'',
      },
      routeQuery: {},
      inspectDetail: {},
//dasdsadsadas
    };
  },
  watch: {},
  computed: {
    isShow() {

      return true

    },
    isEdit() {
      if (this.$route.query.type === "edit") {
        return "write";
      }
      if (this.$route.query.type === "view") {
        return "readonly";
      }
    },
    bool() {
      if (this.$route.query.type === "edit") {
        return true;
      }
      if (this.$route.query.type === "view") {
        return false;
      }
    },
    flowId() {
      if (this.$route.query.flowId) {
        return this.$route.query.flowId === '{flowId}' ? '' : this.$route.query.flowId
      }
    }

  },
  created() {
    this.method = this.$route.query
    this.detailForm.carId = this.$route.query.carId
    let businessDataId = this.method.businessDataId || ''
    this.feedbackList()
    if (!businessDataId) { //  工单id为空
      //this.getWorkOrder()
    }
    if (this.$route.query.types === 'view') {
      this.$nextTick(() => {
        this.inspectDetails(this.$route.query.businessDataId)
      })
    }

  },
  mounted() {
  },
  methods: {
    // 获取基础信息
    async feedbackList() {
      let idList = []
      idList.push(this.method.id)
      try {
        const res = await feedbackList(idList)
        for (let key in this.detailForm) {
          this.detailForm[key] = res[0][key]
        }
        this.inspectDetail =  res[0]
      } catch (e) {
        console.error(e)
      }
    },

    closeSelectedTag(view) {
      this.$tab.closePage(view).then(({visitedViews}) => {
        this.$router.push({
          path: "/cwgd/inspectList",
        })
      })
    },

    getWorkOrder() {
      getWorkOrder(this.method.id).then(res => {
        if (res.code === 200) {
          this.inspectDetail = res.data
        }
      });
    },

    // 提交操作
    submitOn() {
      this.$refs.refDetailForm.handleProcessingAnnual().then(() => {
        const loading = this.$loading({
          lock: true,
          text: '保存中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        this.detailForm.workOrderStatus = "2"
        let businessDataId = this.method.businessDataId
        let id = this.method.id || ''
        this.detailForm.workId = id
        addInspection([this.detailForm]).then((res) => {
          if (res.code === 200) {
            loading.close();
            this.closeSelectedTag(this.$route)
          }
        }).catch(() => {
          loading.close();
        })

      }).catch(err => {

      })
    },

    // 详情回显
    inspectDetails(id) {
      getInspectionDetails(id).then(res => {
        if (res.code === 200) {
          this.isForm = true
          for (let key in res.data) {
            this.$set(this.detailForm, key, res.data[key])
          }
        }
      })
    }
  }
};
</script>


<style lang="scss" scoped>
@import "@/styles/cwgd/container.scss";
</style>
